--TEST--
int MySQLndUhConnection::getFieldCount(resource $connection)
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
	require_once('config.inc');

	class proxy extends MySQLndUhConnection {
		public function getFieldCount($res) {
			printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));
			var_dump($ret = parent::getFieldCount($res));
			return $ret;
		}
	}

	class proxy2 extends MySQLndUhConnection {
		public function getFieldCount($res) {
			return 12;
		}
	}

	class proxy3 extends MySQLndUhConnection {
		public function getFieldCount($res) {
			$ret = new stdClass();
			return $ret;
		}
	}

	class proxy4 extends MySQLndUhConnection {
		public function getFieldCount($res) {}
	}

	class proxy5 extends MySQLndUhConnection {
		public function getFieldCount($res) {
			return PHP_INT_MAX;
		}
	}

	function test_field_count($conn, $offset, $num_fields, $field_count) {

		if (!$conn->query("DROP TABLE IF EXISTS test")) {
			printf("[%03d + 1] [%d] '%s'\n", $offset, $conn->errno, $conn->error);
			return false;
		}

		$fields = $values = $field_names = '';
		for ($i = 0; $i < $num_fields; $i++) {
			$fields .= sprintf("col%d INT, ", $i);
			$field_names .= sprintf("col%d, ", $i);
			$values .= sprintf("%d, ", $i);
		}
		$fields = substr($fields, 0, -2);
		$field_names = substr($field_names, 0, -2);
		$values = substr($values, 0, -2);

		if (!$conn->query($sql = sprintf("CREATE TABLE test(%s)", $fields))
			|| !$conn->query($sql = sprintf("INSERT INTO test(%s) VALUES (%s)", $field_names, $values))
			|| (!($res = $conn->query($sql = "SELECT * FROM test")))) {
			printf("[%03d + 2] [%d] '%s' (%s)\n", $offset, $conn->errno, $conn->error, $sql);
			return false;
		}

		if ($field_count != $conn->field_count) {
			printf("[%03d + 3] Expecting %d got %s\n", $offset, $field_count, $conn->field_count);
			$res->close();
			return false;
		}

		$res->close();

		return true;
	}

	$conn = mysqlnd_uh_test\connect::mysqli();
	mysqlnd_uh_test\query_test::mysqli($conn);
	if (!$conn->query("DROP TABLE IF EXISTS test")
		|| !$conn->query("CREATE TABLE test(id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, col1 SMALLINT)"))
		printf("[001] [%d] '%s'\n", $conn->errno, $conn->error);

	test_field_count($conn, 2, 1, 1);
	mysqlnd_uh_test\query_test::mysqli($conn);

	mysqlnd_uh_set_connection_proxy(new proxy());
	test_field_count($conn, 3, 2, 2);
	mysqlnd_uh_test\query_test::mysqli($conn);

	mysqlnd_uh_set_connection_proxy(new proxy2());
	test_field_count($conn, 4, 2, 12);
	mysqlnd_uh_test\query_test::mysqli($conn);

	$conn = mysqlnd_uh_test\connect::mysqli();
	mysqlnd_uh_set_connection_proxy(new proxy3());
	test_field_count($conn, 5, 1, 3);
	mysqlnd_uh_test\query_test::mysqli($conn);

	$conn = mysqlnd_uh_test\connect::mysqli();
	mysqlnd_uh_set_connection_proxy(new proxy5());
	test_field_count($conn, 7, 2, PHP_INT_MAX);
	mysqlnd_uh_test\query_test::mysqli($conn);

	$conn = mysqlnd_uh_test\connect::mysqli();
	mysqlnd_uh_set_connection_proxy(new proxy4());
	test_field_count($conn, 6, 2, 0);
	mysqlnd_uh_test\query_test::mysqli($conn);

	print "done!";
?>
--EXPECTF--
proxy::getFieldCount(array (
  0 => NULL,
))
int(0)
proxy::getFieldCount(array (
  0 => NULL,
))
int(0)
proxy::getFieldCount(array (
  0 => NULL,
))
int(0)
proxy::getFieldCount(array (
  0 => NULL,
))
int(2)
proxy::getFieldCount(array (
  0 => NULL,
))
int(2)
proxy::getFieldCount(array (
  0 => NULL,
))
int(2)

Warning: mysqli::query(): (00000/0):  in %s on line %d
[004 + 1] [0] ''

Warning: mysqli::query(): (MySQLnd User Handler) The method MySQLndUhConnection::getFieldCount() did not return a numeric value as it should (C type used by mysqlnd: "unsigned int") in %s on line %d

Warning: mysqli::query(): (00000/0):  in %s on line %d
[005 + 1] [0] ''

Warning: mysqli::query(): (MySQLnd User Handler) The method MySQLndUhConnection::getFieldCount() did not return a numeric value as it should (C type used by mysqlnd: "unsigned int") in %s on line %d

Warning: mysqli::query(): (00000/0):  in %s on line %d
[007 + 1] [0] ''

Warning: mysqli::query(): (MySQLnd User Handler) The method MySQLndUhConnection::getFieldCount() did not return a numeric value as it should (C type used by mysqlnd: "unsigned int") in %s on line %d

Warning: mysqli::query(): (MySQLnd User Handler) The method MySQLndUhConnection::getFieldCount() did not return a numeric value as it should (C type used by mysqlnd: "unsigned int") in %s on line 52

Warning: mysqli::query(): (MySQLnd User Handler) The method MySQLndUhConnection::getFieldCount() did not return a numeric value as it should (C type used by mysqlnd: "unsigned int") in %s on line 53

Warning: mysqli::query(): (MySQLnd User Handler) The method MySQLndUhConnection::getFieldCount() did not return a numeric value as it should (C type used by mysqlnd: "unsigned int") in %s on line 54

Warning: test_field_count(): (MySQLnd User Handler) The method MySQLndUhConnection::getFieldCount() did not return a numeric value as it should (C type used by mysqlnd: "unsigned int") in %s on line 59

Fatal error: Call to a member function close() on a non-object in %s on line 65